﻿
@using System.Collections
@using BusinessLibrary

@{ string controller = this.Url.RouteUrl(this.ViewContext.RouteData.Values);
    string nameView = ViewBag.NameView;
}

<style type="text/css">
    #SearchForm td {
        font-size: 15px;
        font-weight: bold;
        background-color: darkcyan;
        color: white
    }
    
    #SearchForm input[type="text"], input[type="checkbox"], select  {
        margin-right: 20px;
    }
    
     #keyName {
         width: 15%;
     }
     
     #keyCode {
         width: 5%;
     }
</style>

@using (Ajax.BeginForm("Search", null, new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "divTableShow" }, new { name = "formSearch" }))
{ 
 @*  <fieldset id="SearchFieldset">
        <legend>Search Form</legend>*@
         @*<input type="hidden" name="view" id = "view" value="@controller" />*@
        <table id="SearchForm">
            <tr>
                <td>Name : @Html.Editor("keyName")
                Code : @Html.Editor("keyCode")
                City : @Html.DropDownList("keyCity", new SelectList(ViewBag.Cities as IEnumerable), string.Empty)
                    District :@Html.DropDownList("keyDistrict", new SelectList(ViewBag.Districts as IEnumerable), string.Empty) 

            @if(Roles.Provider.IsUserInRole(User.Identity.Name,Constants.REVIEWER_ROLE ))
            {
                @: Responsibility : @Html.DropDownList("keyResp", new SelectList(ViewBag.Emps as IEnumerable), string.Empty)
            }
            else
            {
                <a style="visibility: hidden;">@Html.TextArea("keyResp", new { style = "width: 0px; height:0px" })</a>
            }
            
            @if (nameView != "StoreResult")
            {
                <div style="visibility: hidden"> Accepted @Html.CheckBox("keyAccepted") Refused @Html.CheckBox("keyRefused")</div>
            }
            else
            {
                 @:Accepted @Html.CheckBox("keyAccepted") Refused @Html.CheckBox("keyRefused")
            }
                
            @if (controller.ToLower().Equals("/employee") || controller.ToLower().Equals("/employee/index"))
            {
                @:Role : @Html.DropDownList("keyRole", new SelectList(ViewBag.Roles as IEnumerable), string.Empty)
                @:IsLocked @Html.CheckBox("keyIsLocked") Active @Html.CheckBox("keyIsActive")
            }
            </td>
            </tr>
        </table>
        <div style="width: 100%; height: auto; text-align: center; visibility: hidden; display: none"><input type="submit" id="SearchSubmit" value="Search"></div>
    @*</fieldset>*@

}
    
<script type="text/javascript">
    var selector = {
        Name: "#keyName",
        Code: "#keyCode",
        Role : "#keyRole",
        City: "select#keyCity",
        District: "select#keyDistrict"
    };

    $(selector.City).change(function () {
        selectFromAjax('@Url.Action("DistrictList", "Employee")', { city: $(this).find("option:selected").val() }, $(selector.District));
    });

    $("input[type = 'text']").keyup(function () {
        ClickSearchSubmit();
        //console.log("search");
    });
    
    $("input[type = 'checkbox']").click(function () {
        ClickSearchSubmit();
        //console.log("search");
    });

    $("select").change(function () {
        ClickSearchSubmit();
        //console.log("search");
    });

    function ClickSearchSubmit() {
        $("#SearchSubmit").click();
    }

</script>